package com.xln.furn.util;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Token {

    public static String createToken(String name,String password){
        String token = Jwts.builder().signWith(SignatureAlgorithm.HS256, "eHVsaW5pYW4K")
                .addClaims(new HashMap<String, Object>(){{
                    put("userId",name);
                    put("password",password);
                }})
                .setExpiration(new Date(System.currentTimeMillis() + 300 * 1000))
                .compact();
        return token;
    }

    public static Map parseToken(String token){
        Map<String, Object> claims = Jwts.parser().setSigningKey("eHVsaW5pYW4K").parseClaimsJws(token).getBody();
        return claims;
    }


}
